#include "ArcaNoe.h"

ArcaNoe::ArcaNoe(){
        (*this).nrAnimale=0;
        (*this).time=0;
        (*this).index=0;
}
void ArcaNoe::addAnimal(Animal* anim){
        try{    
                                if((*this).nrAnimale<MAX)       
                                {
                                        (*this).animale[index++]=anim;
                                        (*this).nrAnimale++;
                                }
                                else
                                        throw(1);
        }
        catch(int e)
        {
                std::cout<<"\nNu poti adauga mai multe animale!!\n";
        }
}
void ArcaNoe::mananca(){
        for(int i=0;i<nrAnimale;i++)
                for(int j=i+1;j<nrAnimale;j++)
                        if(((animale[i]->getNume())=="Pisica")&&(animale[j]->getNume()=="Soarece"))
                                {
                                        dynamic_cast< Pisica*>(animale[i])->mananca(dynamic_cast< Soarece*>(animale[j]));
                                        (*this).nrAnimale--;
                                        animale[i+1]=animale[i+2];
                                        (*this).index--;
                                }
}
void ArcaNoe::passTime(int nrLuni){
        time=time+nrLuni;
        for(int i=0;i<nrAnimale;i++){
                        animale[i]->addAge(nrLuni);
                        if(animale[i]->getAgeLimit()<animale[i]->getAge())
                                {
                                        if(animale[i]->getNume()=="Pisica")
                                                {
                                                        Pisica *ps;
                                                        ps=dynamic_cast< Pisica*>(animale[i]);
                                                        ps->~Pisica();
                                                }
                                        if(animale[i]->getNume()=="Soarece")
                                                {
                                                        Soarece *ps;
                                                        ps=dynamic_cast< Soarece*>(animale[i]);
                                                        ps->~Soarece();
                                                }
                                        if(animale[i]->getNume()=="Crap")
                                                {
                                                        Crap *ps;
                                                        ps=dynamic_cast< Crap*>(animale[i]);
                                                        Crap->~Crap();
                                                }
                                        if(animale[i]->getNume()=="Balena")
                                                {
                                                        Balena *ps;
                                                        ps=dynamic_cast< Balena*>(animale[i]);
                                                        ps->~Balena();
                                                }
                                        if(animale[i]->getNume()=="Crocodil")
                                                {
                                                        Crocodil *ps;
                                                        ps=dynamic_cast< Crocodil*>(animale[i]);
                                                        ps->~Crocodil();
                                                }
                                        if(animale[i]->getNume()=="Cioara")
                                                {
                                                        Cioara *ps;
                                                        ps=dynamic_cast< Cioara*>(animale[i]);
                                                        ps->~Cioara();
                                                }
                                        if(animale[i]->getNume()=="Stiuca")
                                                {
                                                        Stiuca *ps;
                                                        ps=dynamic_cast< Stiuca*>(animale[i]);
                                                        ps->~Stiuca();
                                                }
                                        if(animale[i]->getNume()=="Ornitorinc")
                                                {
                                                        Ornitorinc *ps;
                                                        ps=dynamic_cast< Ornitorinc*>(animale[i]);
                                                        ps->~Ornitorinc();
                                                }
                                        if(animale[i]->getNume()=="Papagal")
                                                {
                                                        Papagal *ps;
                                                        ps=dynamic_cast< Papagal*>(animale[i]);
                                                        ps->~Papagal();
                                                }
                                }
        }
        
}
